#!/bin/sh

set -e

if ! hash apt-get 2>/dev/null; then
	whiptail --title "Orangepi Build System" --msgbox "This scripts requires a Debian based distrbution. If you not use Debian/Ubunut, pls install:[ bsdtar mtools u-boot-tools pv bc sunxi-tools gcc automake make qemu dosfstools ]"
	exit 1
fi
export NEEDRESTART_MODE=a
apt-get -y --no-install-recommends --fix-missing install \
	libarchive-tools mtools u-boot-tools pv bc \
	gcc automake make libssl-dev\
	curl lib32z1 liblz4-tool lib32z1-dev qemu-user-static \
	dosfstools figlet device-tree-compiler debootstrap python2 gcc-9 g++-9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9
sudo update-alternatives --config gcc
apt-get install --reinstall qemu-user-static binfmt-support
